<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ include file="/WEB-INF/jsp/inc/taglib.jsp" %>
<%-- 设置URL参数 --%>
<c:set var="queryURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}" />
<c:set var="viewURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/{0}" />
<c:set var="createURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/create" />
<c:set var="updateURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/{0}/update" />
<c:set var="deleteURL" value="${r'${ctx }' }${baseURL}/${domainObjectName?uncap_first}/{0}/delete" />

<c:set var="searchPage" value="query.jsp" />
<c:set var="modelMessageKey" value="${domainObjectName?uncap_first}" />
<%-- 权限设置 --%>
<c:set var="createPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:create" />
<c:set var="updatePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:update" />
<c:set var="deletePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:delete" />
<c:set var="viewPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:view" />

<!DOCTYPE html>
<html>
<head>
<title><fmt:message key="${domainObjectName?uncap_first }" /></title>
<%@ include file="/WEB-INF/jsp/inc/inc-head.jsp"%>
<%@ include file="/WEB-INF/jsp/inc/inc-css.jsp"%>
</head>
<body>
<div class="crud">
	<shiro:hasPermission name="${r'${viewPermission}'}">
    <input type="button" onclick="query()" value="<fmt:message key="global.button.query"/>"/>
    </shiro:hasPermission>
	<shiro:hasPermission name="${r'${createPermission}'}">
    <input type="button" onclick="createModel();" value="<fmt:message key="global.button.add"/>"/>
    </shiro:hasPermission>
	<shiro:hasPermission name="${r'${updatePermission}'}">
    <input type="button" onclick="selectModel();" value="<fmt:message key="global.button.select"/>"/>
    </shiro:hasPermission>
	<shiro:hasPermission name="${r'${deletePermission}'}">
    <input type="button" onclick="deleteModel();" value="<fmt:message key="global.button.delete"/>"/>
    </shiro:hasPermission>
</div>
<div class="datalist">
	<jsp:include page="${r'${searchPage }'}" />
	<div class="datagrid">
		<table id="dataGrid" class="table"/>
	</div>
</div>
</body>
</html>
<%@ include file="/WEB-INF/jsp/inc/inc.jsp"%>
<%@ include file="/WEB-INF/jsp/common/messager.jsp" %>
<script type="text/javascript">
var queryParams={"first":true};
var columns = [
<#assign flag = true />
<#list table.allColumns as column>
	<#if !(primaryKeyColumns?seq_contains(column))>
		<#if flag >
			<#assign flag=false />
 {width : "100",align : "left", halign : "center", valign : 'middle', sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		<#else />
,{width : "100",align : "left", halign : "center", valign : 'middle', sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		</#if>	
	</#if>
</#list>
	];
<shiro:hasPermission name="${r'${viewPermission}'}">
$(function() {
	$('#dataGrid').table({
		url : '${r'${queryURL }' }', 
		columns:columns,
		onDblClickRow : function(row, $element){
			if(selectModel){selectModel(row.${primaryKeyColumns[0].javaProperty });}
		}
	});
});
function query(){
	$('#dataGrid').bootstrapTable('refresh')
}
</shiro:hasPermission>
var selectModel,createModel,updateModel,deleteModel,viewModel;
selectModel = function(id){
	if(updateModel)
		updateModel(id);
	else if(viewModel)
		viewModel(id);
}
<shiro:hasPermission name="${r'${createPermission}'}">
createModel = function() {
	parent.changeURL("${r'${createURL}' }");
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${viewPermission}'}">
viewModel = function(id) {
	if(!id){
		var row = getDataGridSelected($('#dataGrid'));
		if(!row){
			msgWarning($.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>')); 
			return;
		}
		id = row.${primaryKeyColumns[0].javaProperty};
	}
	parent.changeURL($.formatString("${r'${viewURL}' }",id));
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${updatePermission}'}">
updateModel = function(id) {
	if(!id){
		var row = getDataGridSelected($('#dataGrid'));
		if(!row){
			msgWarning($.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>')); 
			return;
		}
		id = row.${primaryKeyColumns[0].javaProperty};
	}
	parent.changeURL($.formatString("${r'${updateURL}' }",id));
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${deletePermission}'}">
deleteModel = function(id) {
	if(!id){
		var row = getDataGridSelected($('#dataGrid'));
		if(!row){
			msgWarning($.formatString('<fmt:message key="global.show.message.delete"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'));
			return;
		}
		id = row.${primaryKeyColumns[0].javaProperty};
	}
	layer.confirm($.formatString('<fmt:message key="global.confirm.message"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), {icon: 3, title:'<fmt:message key="global.confirm.title"/>'}, function(index){
		parent.changeURL($.formatString("${r'${deleteURL}' }",id));
	});
};
</shiro:hasPermission>
</script>